home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / LIB / GLE / ROTATE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  3.6 KB  |  134 lines

  1. /* 
  2.  * MODULE NAME: rotate.c
  3.  *
  4.  * FUNCTION:
  5.  * This module contains three different routines that compute rotation
  6.  * matricies and load them into GL.
  7.  * Detailed description is provided below.
  8.  *
  9.  * DEPENDENCIES:
  10.  * The routines call GL matrix routines.
  11.  *
  12.  * HISTORY:
  13.  * Developed & written, Linas Vepstas, Septmeber 1991
  14.  * Double precision port, March 1993
  15.  *
  16.  * DETAILED DESCRIPTION:
  17.  * This module contains three routines:
  18.  * --------------------------------------------------------------------
  19.  *
  20.  * void urot_about_axis (float m[4][4],      --- returned
  21.  *                       float angle,        --- input 
  22.  *                       float axis[3])      --- input
  23.  * Computes a rotation matrix.
  24.  * The rotation is around the the direction specified by the argument
  25.  * argument axis[3].  User may specify vector which is not of unit
  26.  * length.  The angle of rotation is specified in degrees, and is in the
  27.  * right-handed direction.
  28.  *
  29.  * void rot_about_axis (float angle,        --- input 
  30.  *                      float axis[3])      --- input
  31.  * Same as above routine, except that the matrix is multiplied into the
  32.  * GL matrix stack.
  33.  *
  34.  * --------------------------------------------------------------------
  35.  *
  36.  * void urot_axis (float m[4][4],      --- returned
  37.  *                 float omega,        --- input
  38.  *                 float axis[3])      --- input
  39.  * Same as urot_about_axis(), but angle specified in radians.
  40.  * It is assumed that the argument axis[3] is a vector of unit length.
  41.  * If it is not of unit length, the returned matrix will not be correct.
  42.  *
  43.  * void rot_axis (float omega,        --- input
  44.  *                float axis[3])      --- input
  45.  * Same as above routine, except that the matrix is multiplied into the
  46.  * GL matrix stack.
  47.  *
  48.  * --------------------------------------------------------------------
  49.  *
  50.  * void urot_omega (float m[4][4],       --- returned
  51.  *                  float omega[3])      --- input
  52.  * same as urot_axis(), but the angle is taken as the length of the
  53.  * vector omega[3]
  54.  *
  55.  * void rot_omega (float omega[3])      --- input
  56.  * Same as above routine, except that the matrix is multiplied into the
  57.  * GL matrix stack.
  58.  *
  59.  * --------------------------------------------------------------------
  60.  */
  61.  
  62. #include "gutil.h"
  63. #include "port.h"
  64.    
  65. /* ========================================================== */
  66.  
  67. #ifdef __GUTIL_DOUBLE
  68. void rot_axis_d (double omega,         /* input */
  69.                double axis[3])        /* input */
  70. {
  71.    double m[4][4];
  72.  
  73.    (void) urot_axis_d (m, omega, axis);
  74.    MULTMATRIX_D (m);
  75.  
  76. }
  77. #else 
  78.  
  79. void rot_axis_f (float omega,         /* input */
  80.                float axis[3])        /* input */
  81. {
  82.    float m[4][4];
  83.  
  84.    (void) urot_axis_f (m, omega, axis);
  85.    MULTMATRIX_F (m);
  86.  
  87. }
  88. #endif 
  89.  
  90. /* ========================================================== */
  91.  
  92. #ifdef __GUTIL_DOUBLE
  93. void rot_about_axis_d (double angle,         /* input */
  94.                        double axis[3])        /* input */
  95. {
  96.    double m[4][4];
  97.  
  98.    (void) urot_about_axis_d (m, angle, axis);
  99.    MULTMATRIX_D (m);
  100. }
  101.  
  102. #else
  103. void rot_about_axis_f (float angle,         /* input */
  104.                        float axis[3])        /* input */
  105. {
  106.    float m[4][4];
  107.  
  108.    (void) urot_about_axis_f (m, angle, axis);
  109.    MULTMATRIX_F (m);
  110. }
  111. #endif
  112.  
  113. /* ========================================================== */
  114.  
  115. #ifdef __GUTIL_DOUBLE
  116. void rot_omega_d (double axis[3])        /* input */
  117. {
  118.    double m[4][4];
  119.  
  120.    (void) urot_omega_d (m, axis);
  121.    MULTMATRIX_D(m);
  122. }
  123. #else
  124. void rot_omega_f (float axis[3])        /* input */
  125. {
  126.    float m[4][4];
  127.  
  128.    (void) urot_omega_f (m, axis);
  129.    MULTMATRIX_F(m);
  130. }
  131. #endif
  132.  
  133. /* ========================================================== */
  134.